﻿using AutoMapper;
using EasyI18n.Api.Infrastructure.DataPersistence.MongoDb.Entities;
using EasyI18n.Api.Primary.Bases;
using EasyI18n.Api.Primary.Contracts.Bases;
using Mediator.Net.Contracts;
using MongoDB.Bson;

namespace EasyI18n.Api.Primary.Contracts.LanguageDictContracts;

public interface ICreateLanguageDictContract : ICommandContract<CreateLanguageDictCommand>;

public class CreateLanguageDictCommand : ICommand, IMapFrom<LanguageDict>
{
    public Guid ProjectId { get; set; }
    public string WordId { get; set; }
    public List<LanguageProperty> LanguageWords { get; set; }

    public void ConfigureMapper(IMapperConfigurationExpression cfg, LanguageDict? source)
    {
        this.CreateMapperConfiguration(cfg, source)
            .ForMember(x => x.ProjectId, x => x.MapFrom(e => e.ProjectId.ToString()))
            .ReverseMap()
            .ForMember(x => x.ProjectId, x => x.MapFrom(e => ObjectId.Parse(e.ProjectId.ToString())));
    }
}